package com.my.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.my.admin.entity.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author my
 */
public interface MenuMapper extends BaseMapper<Menu> {

    /**
     * @param userId
     * @return 菜单
     */
    @Select("select m.id, m.parent_id, m.name, m.url, m.icon from user u, user_role ur, role r, role_menu r_m, menu m where ur.user_id = r.id and r.id = r_m.role_id and r_m.menu_id = m.id and u.is_delete = false and ur.is_delete = false and r.is_delete = false and r_m.is_delete = false and m.is_delete = false and u.id = #{userId};")
    List<Menu> getMenuByUserId(@Param("userId") Long userId);

    @Select("SELECT m. id, m.name, m.parent_id, m.url, m.code, m.icon, m.deep, m.sort, m.is_delete, m.create_time, m.update_time, p.name as parentName FROM menu m LEFT JOIN menu p ON m.parent_id = p.id WHERE m.is_delete=false")
    List<Menu> getList();

}
